package com.yy.wga.admin.service.controller;

import com.yy.wga.common.core.dto.PageBean;
import com.yy.wga.common.core.dto.Result;
import com.yy.wga.common.mysql.util.PageUtil;
import com.yy.wga.common.utils.mapping.BeansUtils;
import com.yy.wga.mp.module.goods.response.GoodsInfoResp;
import com.yy.wga.mp.module.resource.request.ResourceGoodsCategoryReq;
import com.yy.wga.mp.module.resource.response.GetAllCategoryGoodsResp;
import com.yy.wga.mp.module.resource.response.GetHeadSupplierGoodsResponse;
import com.yy.wga.mp.module.resource.response.GetPageCategoryGoodsResp;
import com.yy.wga.mp.module.resource.response.GetResourceGoodsCategoryResponse;
import com.yy.wga.resource.feign.api.ResourceGoodsCategoryFeign;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 资源商品分类管理
 */
@RestController
@RequestMapping("api/resource/goods/category")
public class AdminResourceGoodsCategoryController {

    @Resource
    private ResourceGoodsCategoryFeign resourceGoodsCategoryFeign;

    /**
     * 添加分类
     * @param request
     * @return
     */
    @PostMapping(value = "/addCategory")
    public Result<Void> addCategory(@RequestBody @Valid ResourceGoodsCategoryReq.AddCategory request) {
        com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.AddCategory addCategory = com.yy.wga.common.utils.mapping.BeansUtils.map(request, com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.AddCategory.class);
        return resourceGoodsCategoryFeign.addCategory(addCategory);
    }

    /**
     * 更新分类
     * @param request
     * @return
     */
    @PostMapping(value = "/updateCategory")
    public Result<Void> updateCategory(@RequestBody @Valid ResourceGoodsCategoryReq.UpdateCategory request) {
        com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.UpdateCategory addCategory = com.yy.wga.common.utils.mapping.BeansUtils.map(request, com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.UpdateCategory.class);
        return resourceGoodsCategoryFeign.updateCategory(addCategory);
    }

    /**
     * 删除分类
     * @param request
     * @return
     */
    @PostMapping(value = "/deleteCategory")
    public Result<Void> deleteCategory(@RequestBody @Valid ResourceGoodsCategoryReq.DeleteCategory request) {
        com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.DeleteCategory addCategory = com.yy.wga.common.utils.mapping.BeansUtils.map(request, com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.DeleteCategory.class);
        return resourceGoodsCategoryFeign.deleteCategory(addCategory);
    }

    /**
     * 查看所有品类
     * @return
     */
    @GetMapping(value = "/listCategory")
    public Result<List<GetResourceGoodsCategoryResponse>> listCategory() {
        Result<List<com.yy.wga.resource.feign.response.GetResourceGoodsCategoryResponse>> result = resourceGoodsCategoryFeign.listCategory();
        if (result.isSuccess()) {
            List<com.yy.wga.resource.feign.response.GetResourceGoodsCategoryResponse> data = result.getData();
            List<GetResourceGoodsCategoryResponse> list = BeansUtils.mapList(data, GetResourceGoodsCategoryResponse.class);
            return Result.success(list);
        }
        return Result.fail(result.getCode(), result.getMessage());
    }

    /**
     * 分类排序
     * @param request
     * @return
     */
    @PostMapping(value = "/sortCategory")
    public Result<Void> sortCategory(@RequestBody @Valid ResourceGoodsCategoryReq.SortCategory request) {
        com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.SortCategory addCategory = com.yy.wga.common.utils.mapping.BeansUtils.map(request, com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.SortCategory.class);
        return resourceGoodsCategoryFeign.sortCategory(addCategory);
    }

    /**
     * 更改分类状态
     * @param request
     * @return
     */
    @PostMapping(value = "/changeCategoryStatus")
    public Result<Void> changeCategoryStatus(@RequestBody @Valid ResourceGoodsCategoryReq.ChangeCategoryStatus request) {
        com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.ChangeCategoryStatus addCategory = com.yy.wga.common.utils.mapping.BeansUtils.map(request, com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.ChangeCategoryStatus.class);
        return resourceGoodsCategoryFeign.changeCategoryStatus(addCategory);
    }

    /**
     * 更改首页展示状态
     * @param request
     * @return
     */
    @PostMapping(value = "/changeHomepageDisplay")
    public Result<Void> changeHomepageDisplay(@RequestBody @Valid ResourceGoodsCategoryReq.ChangeHomepageDisplay request) {
        com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.ChangeHomepageDisplay addCategory = com.yy.wga.common.utils.mapping.BeansUtils.map(request, com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.ChangeHomepageDisplay.class);
        return resourceGoodsCategoryFeign.changeHomepageDisplay(addCategory);
    }

    /**
     * 修改首页是否支持每单补贴佣金格式
     * @param request
     * @return
     */
    @PostMapping(value = "/changeSupportSubsidyAmount")
    public Result<Void> changeSupportSubsidyAmount(@RequestBody @Valid ResourceGoodsCategoryReq.ChangeSupportSubsidyAmount request) {
        com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.ChangeSupportSubsidyAmount addCategory = com.yy.wga.common.utils.mapping.BeansUtils.map(request, com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.ChangeSupportSubsidyAmount.class);
        return resourceGoodsCategoryFeign.changeSupportSubsidyAmount(addCategory);
    }


    /**
     * 添加分类下的商品
     * @param request
     * @return
     */
    @PostMapping(value = "/addGoods")
    public Result<Void> addGoods(@RequestBody @Valid ResourceGoodsCategoryReq.AddGoods request) {
        com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.AddGoods addCategory = com.yy.wga.common.utils.mapping.BeansUtils.map(request, com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.AddGoods.class);
        return resourceGoodsCategoryFeign.addGoods(addCategory);
    }

    /**
     * 删除分类下的商品
     * @param request
     * @return
     */
    @PostMapping(value = "/deleteGoods")
    public Result<Void> deleteGoods(@RequestBody @Valid ResourceGoodsCategoryReq.DeleteGoods request) {
        com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.DeleteGoods deleteGoods = com.yy.wga.common.utils.mapping.BeansUtils.map(request, com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.DeleteGoods.class);
        return resourceGoodsCategoryFeign.deleteGoods(deleteGoods);
    }

    /**
     * 分页查看分类下的商品
     * @param request
     * @return
     */
    @PostMapping(value = "/pageGoods")
    public Result<PageBean<GetPageCategoryGoodsResp>> pageGoods(@RequestBody @Valid ResourceGoodsCategoryReq.PageGoods request) {
        com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.PageGoods deleteGoods = com.yy.wga.common.utils.mapping.BeansUtils.map(request, com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.PageGoods.class);
        Result<PageBean<com.yy.wga.resource.feign.response.GetPageCategoryGoodsResp>> result = resourceGoodsCategoryFeign.pageGoods(deleteGoods);
        if (result.isSuccess()) {
            PageBean<com.yy.wga.resource.feign.response.GetPageCategoryGoodsResp> data = result.getData();
            List<GetPageCategoryGoodsResp> list = BeansUtils.mapList(data.getList(), GetPageCategoryGoodsResp.class);
            PageBean<GetPageCategoryGoodsResp> pageBean = PageUtil.setPageInfo(data);
            pageBean.setList(list);
            return Result.success(pageBean);
        }
        return Result.fail(result.getCode(), result.getMessage());
    }

    /**
     * 分页查看分类下的商品
     * @param request
     * @return
     */
    @PostMapping(value = "/allGoods")
    public Result<List<GetAllCategoryGoodsResp>> allCategoryGoods(@RequestBody @Valid ResourceGoodsCategoryReq.AllGoods request) {
        com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.AllGoods req = BeansUtils.map(request, com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.AllGoods.class);
        Result<List<com.yy.wga.resource.feign.response.GetAllCategoryGoodsResp>> result = resourceGoodsCategoryFeign.allCategoryGoods(req);
        if (result.isSuccess()) {
            List<com.yy.wga.resource.feign.response.GetAllCategoryGoodsResp> respList = result.getData();
            List<GetAllCategoryGoodsResp> list = BeansUtils.mapList(respList, GetAllCategoryGoodsResp.class);
            return Result.success(list);
        }
        return Result.fail(result.getCode(), result.getMessage());
    }

    /**
     * 分类下的商品排序
     * @param request
     * @return
     */
    @PostMapping(value = "/sortGoods")
    public Result<Void> sortGoods(@RequestBody @Valid ResourceGoodsCategoryReq.SortGoods request) {
        com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.SortGoods deleteGoods = com.yy.wga.common.utils.mapping.BeansUtils.map(request, com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.SortGoods.class);
        return resourceGoodsCategoryFeign.sortGoods(deleteGoods);
    }

    /**
     * 设置商品推荐理由
     * @param request
     * @return
     */
    @PostMapping(value = "/setRecommendReason")
    public Result<Void> setRecommendReason(@RequestBody @Valid ResourceGoodsCategoryReq.SetRecommendReason request) {
        com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.SetRecommendReason deleteGoods = com.yy.wga.common.utils.mapping.BeansUtils.map(request, com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.SetRecommendReason.class);
        return resourceGoodsCategoryFeign.setRecommendReason(deleteGoods);
    }

    /**
     * 设置商品补贴金额
     * @param request
     * @return
     */
    @PostMapping(value = "/setSubsidyAmount")
    public Result<Void> setSubsidyAmount(@RequestBody @Valid ResourceGoodsCategoryReq.SetSubsidyAmount request) {
        com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.SetSubsidyAmount deleteGoods = com.yy.wga.common.utils.mapping.BeansUtils.map(request, com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.SetSubsidyAmount.class);
        return resourceGoodsCategoryFeign.setSubsidyAmount(deleteGoods);
    }

    /**
     * 获取微信后台合作商品
     * @param request
     * @return
     */
    @PostMapping(value = "/getHeadSupplierGoods")
    public Result<GetHeadSupplierGoodsResponse> getHeadSupplierGoods(@RequestBody @Valid ResourceGoodsCategoryReq.GetHeadSupplierGoodsReq request) {
        com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.GetHeadSupplierGoodsReq req = BeansUtils.map(request, com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.GetHeadSupplierGoodsReq.class);
        Result<com.yy.wga.resource.feign.response.GetHeadSupplierGoodsResponse> result = resourceGoodsCategoryFeign.getHeadSupplierGoods(req);
        if (result.isSuccess()) {
            com.yy.wga.resource.feign.response.GetHeadSupplierGoodsResponse resp = result.getData();
            GetHeadSupplierGoodsResponse response = BeansUtils.map(resp, GetHeadSupplierGoodsResponse.class);
            return Result.success(response);
        }
        return Result.fail(result.getCode(), result.getMessage());
    }

    /**
     * 获取微信后台合作商品V2
     * @param request
     * @return
     */
    @PostMapping(value = "/getHeadSupplierGoodsV2")
    public Result<PageBean<GoodsInfoResp>> getHeadSupplierGoodsV2(@RequestBody @Valid ResourceGoodsCategoryReq.GetHeadSupplierGoodsReqV2 request) {
        com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.GetHeadSupplierGoodsReqV2 deleteGoods = com.yy.wga.common.utils.mapping.BeansUtils.map(request, com.yy.wga.resource.feign.request.ResourceGoodsCategoryReq.GetHeadSupplierGoodsReqV2.class);
        Result<PageBean<com.yy.wga.resource.feign.response.GoodsInfoResp>> result = resourceGoodsCategoryFeign.getHeadSupplierGoodsV2(deleteGoods);
        if (result.isSuccess()) {
            PageBean<com.yy.wga.resource.feign.response.GoodsInfoResp> data = result.getData();
            List<GoodsInfoResp> list = BeansUtils.mapList(data.getList(), GoodsInfoResp.class);
            PageBean<GoodsInfoResp> pageBean = PageUtil.setPageInfo(data);
            pageBean.setList(list);
            return Result.success(pageBean);
        }
        return Result.fail(result.getCode(), result.getMessage());
    }

}
